{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "14c7059b-f86f-449e-87dc-632a69f22c02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pygame 2.6.1 (SDL 2.28.4, Python 3.11.12)\n",
      "Hello from the pygame community. https://www.pygame.org/contribute.html\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/kun/data/repo/python_note/.venv/lib/python3.11/site-packages/pygame/pkgdata.py:25: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n",
      "  from pkg_resources import resource_stream, resource_exists\n"
     ]
    }
   ],
   "source": [
    "import sys, pygame\n",
    "from pygame import K_ESCAPE, K_q\n",
    "import atexit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "95e9407f-b3be-4cc4-99c7-a96f1dfe00ff",
   "metadata": {},
   "outputs": [
    {
     "ename": "error",
     "evalue": "display Surface quit",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31merror\u001b[39m                                     Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 31\u001b[39m\n\u001b[32m     28\u001b[39m             pygame.quit()\n\u001b[32m     30\u001b[39m \u001b[38;5;66;03m# fill the screen with a color to wipe away anything from last frame\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m31\u001b[39m \u001b[43mscreen\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfill\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblack\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m     33\u001b[39m \u001b[38;5;66;03m# RENDER YOUR GAME HERE\u001b[39;00m\n\u001b[32m     34\u001b[39m screen.blit(text, text_rect)\n",
      "\u001b[31merror\u001b[39m: display Surface quit"
     ]
    }
   ],
   "source": [
    "pygame.init()\n",
    "screen = pygame.display.set_mode((1280, 720))\n",
    "clock = pygame.time.Clock()\n",
    "\n",
    "font = pygame.font.Font(None,36)\n",
    "\n",
    "black = (0,0,0)\n",
    "white = (255,255,255)\n",
    "\n",
    "text = font.render(\"Hello Pygame!\", True, white)\n",
    "text_rect = text.get_rect()\n",
    "text_rect.center = (1280/2, 720/2)\n",
    "def quit_game():\n",
    "    pygame.quit()\n",
    "    sys.exit()\n",
    "\n",
    "atexit.register(quit_game)\n",
    "\n",
    "running = True\n",
    "while running:\n",
    "    # poll for events\n",
    "    # pygame.QUIT event means the user clicked X to close your window\n",
    "    for event in pygame.event.get():\n",
    "        if event.type == pygame.QUIT:\n",
    "            pygame.quit()\n",
    "        if event.type == pygame.KEYDOWN:\n",
    "            if event.key == K_ESCAPE or event.key==K_q:\n",
    "                pygame.quit()\n",
    "\n",
    "    # fill the screen with a color to wipe away anything from last frame\n",
    "    screen.fill(black)\n",
    "\n",
    "    # RENDER YOUR GAME HERE\n",
    "    screen.blit(text, text_rect)\n",
    "\n",
    "    # flip() the display to put your work on screen\n",
    "    pygame.display.flip()\n",
    "\n",
    "    clock.tick(60)  # limits FPS to 60\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f8136e7-33c8-4ea1-8dd6-2888bbcfc2c4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Py(Python note)",
   "language": "python",
   "name": "pynote"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
